//
//  LGStatus.m
//  微博
//
//  Created by MS on 15-12-6.
//  Copyright (c) 2015年 MS. All rights reserved.
//

#import "LGStatus.h"
#import "LGPhoto.h"
#import "NSDate+MJ.h"
@implementation LGStatus

//实现该方法，就会自动把数组中的字典转换成对应的模型
+(NSDictionary *)objectClassInArray
{
    
    return @{@"pic_urls":[LGPhoto class]};
    
}


-(NSString *)created_at
{
    //Wed Dec 23 10:26:31 +0800 2015
    //日期格式字符串
    NSDateFormatter * fmat = [[NSDateFormatter alloc] init];
    fmat.dateFormat = @"EEE MMM d HH:mm:ss Z yyyy";
    
    //设置日期格式本地化，日期格式字符串知道是哪个国籍的日期
    fmat.locale = [NSLocale localeWithLocaleIdentifier:@"en_us"];
   
    NSDate * create_date = [fmat dateFromString:_created_at];
    if ([create_date isThisYear
        ]) {//今年
        if ([create_date isToday]) {//今天
            
            //计算跟当前时间差距
            NSDateComponents * cmp = [create_date deltaWithNow];
//            NSLog(@"%ld-%ld-%ld",cmp.hour,cmp.minute,cmp.second);
            if (cmp.hour>=1) {
                return [NSString stringWithFormat:@"%ld小时前",cmp.hour];
            }
            else if (cmp.minute>1){
                return [NSString stringWithFormat:@"%ld分钟前",cmp.minute];
            }
            else{
                return @"刚刚";
            }
            
        }
        else if ([create_date isYesterday]){//昨天
            
            fmat.dateFormat = @"昨天 HH:mm";
            return [fmat stringFromDate:create_date];
        }
        else{//前天
            
            fmat.dateFormat = @"MM-dd HH:mm";
            return [fmat stringFromDate:create_date];
        }
    }
    else{//不是今年
        
        fmat.dateFormat = @"yyyy-MM-dd HH:mm";
        return [fmat stringFromDate:create_date];
    }
    
    
//    NSLog(@"%@",_created_at);
    return _created_at;
}

-(void)setSource:(NSString *)source
{
    /**
     *
     2015-12-23 15:30:32.583 微博[1694:37470] <a href="http://app.weibo.com/t/feed/2fvBFo" rel="nofollow">南方周末</a>
     */
    NSRange rang = [source rangeOfString:@">"];
     source = [source substringFromIndex:rang.location+rang.length];
    
    NSRange range = [source rangeOfString:@"<"];
    source = [source substringToIndex:range.location];
    source = [NSString stringWithFormat:@"来自%@",source];
    
    _source = source;
}


@end
